import { defHttp } from '/@/utils/http/axios';
import { LoginParams, LoginResultModel, GetUserInfoModel } from './model/userModel';

import { ErrorMessageMode } from '/#/axios';

enum Api {
  Login = '/inyaa-admin/login',
  Logout = '/inyaa-admin/logout',
  GetUserInfo = '/inyaa-admin/user/info',
  GetPermCode = '/inyaa-admin/getPermCode',
  FindUserList = '/inyaa-admin/user/list',
  SaveUser = '/inyaa-admin/user/save',
  DeleteUser = '/inyaa-admin/user/delete',
}

/**
 * @description: user login api
 */
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      url: Api.Login,
      params,
      headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' },
    },
    {
      errorMessageMode: mode,
    }
  );
}

/**
 * @description: getUserInfo
 */
export function getUserInfo() {
  return defHttp.get<GetUserInfoModel>({ url: Api.GetUserInfo });
}

export function findUserList() {
  return defHttp.get<GetUserInfoModel>({ url: Api.FindUserList });
}

export function saveUser(user: GetUserInfoModel) {
  return defHttp.post<GetUserInfoModel>({ url: Api.SaveUser, params: user });
}

export function deleteUser(user: GetUserInfoModel) {
  return defHttp.post<GetUserInfoModel>({ url: Api.DeleteUser, params: user });
}

export function getPermCode() {
  return defHttp.get<string[]>({ url: Api.GetPermCode });
}

export function doLogout() {
  return defHttp.get({ url: Api.Logout });
}
